/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package samoloty.controler;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

/**
 *
 * @author borysfan
 */
public class PrintDisplayPanel implements Printable{
    private String text;

    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex > 0){
            System.out.println("nie drukuje...");
            return NO_SUCH_PAGE;
        }
        System.out.println("drukuje...");
          System.out.println(text);
          Font font = new Font("monospaced",Font.PLAIN,10);
          Graphics2D g2 = (Graphics2D)graphics;
          g2.setFont(font);
          g2.setColor(Color.BLACK);
          int x=100;
          int y=100;
          
          
          String [] lines = text.split("\n");
          for(int i=0;i<lines.length;i++){
              g2.drawString(lines[i], x, y);
              y+=14;
          }

          System.out.println(pageIndex + " " + pageFormat.getWidth() + " " + pageFormat.getHeight());
          return PAGE_EXISTS;
    }

    public void setText(String s){
        text = s;
    }

}
